package com.tsing.cedap.rest.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tsing.cedap.rest.entity.CourierStationEntity;
import com.tsing.cedap.rest.vo.respVo.CampusTreeRespVo;
import com.tsing.cedap.rest.vo.respVo.IdAndNameRespVo;
import com.tsing.cedap.rest.vo.respVo.StationRespVo;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 驿站表 Mapper 接口
 * </p>
 *
 * @author TheTsing
 * @since 2022-01-26
 */
public interface CourierStationMapper extends BaseMapper<CourierStationEntity> {

    @Select("select cs.id,concat(c.name,' - ',cs.name) name\n" +
            "from cedap_courier_station cs\n" +
            "inner join cedap_campus c on cs.campus_id=c.id\n" +
            "where c.id=#{id}\n" +
            "order by cs.id desc")
    @Result(property = "children", column = "id", many = @Many(select = "getBrandById"))
    List<CampusTreeRespVo> courierStationTree(@Param("id") String code);

    @Select("select id,name from cedap_express_brand where courier_station_id=#{id} order by id desc")
    List<IdAndNameRespVo> getBrandById(@Param("id") String id);

    @Select("select c.*,ca.*\n" +
            "from cedap_courier_station c\n" +
            "inner join cedap_campus ca on c.campus_id=ca.id where c.id=#{id}")
    StationRespVo getStation(@Param("id") String code);

}